package com.meiqiongproperty.yiguanjia.fragment.personalCenter;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.meiqiongproperty.yiguanjia.R;
import com.meiqiongproperty.yiguanjia.databinding.ModifyPasswordLayoutBinding;
import com.meiqiongproperty.yiguanjia.fragment.BaseFragment;
import com.meiqiongproperty.yiguanjia.http.api.ApiService;
import com.meiqiongproperty.yiguanjia.http.interfaces.IHttpCallback;
import com.meiqiongproperty.yiguanjia.http.sendJsonModel.SendModifyPwd;
import com.meiqiongproperty.yiguanjia.httpbean.user.ForGetpassword;
import com.meiqiongproperty.yiguanjia.utils.Utils;

/**
 * author: Administrator
 * date: 2017/5/18.
 * package:com.meiqiongproperty.yiguanjia.fragment.personalCenter
 */

public class ModifyPwdFragment extends BaseFragment {
    ModifyPasswordLayoutBinding binding;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.modify_password_layout, container, false);

        binding.navigation.setTitle("修改密码");
        binding.navigation.setLeftClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendKeyBackEvent();
            }
        });

        binding.btnConfirmModifyPwd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                modifyPassword();
            }
        });
        return binding.getRoot();
    }

    /**
     * 修改密码
     */
    public void modifyPassword() {
        SendModifyPwd send = new SendModifyPwd();
        send.setMobile(Utils.getUserPhoneNumber(getActivity()));
        send.setOldPwd(binding.etOrginPassword.getText().toString());
        send.setNewPwd(binding.etNewPassword.getText().toString());

        ApiService.ModifyPassword(getActivity(), new IHttpCallback<ForGetpassword>() {
            @Override
            public void onNext(ForGetpassword forGetpassword) {
                Toast.makeText(getActivity(), "修改成功", Toast.LENGTH_SHORT).show();
                sendKeyBackEvent();
            }

            @Override
            public void onError(int code, String message) {

            }
        }, Utils.getRequestBody(send));
    }
}
